package com.jilujia.domain.question;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.NotEmpty;

import com.jilujia.framework.domain.PoEntity;

@Entity
@Table(name = "TB_QUESTION")
public class Question implements PoEntity<Long>, Serializable {
	// TODO validate tag1,2,3..大小1-15，可以为null，不能有标点符号
	/**
	 * 
	 */
	private static final long serialVersionUID = 6318228532671136749L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@NotEmpty()
	@Column(nullable = false, length = 100)
	private String title;

	@Column(nullable = false)
	private Long userId;

	@Column(nullable = false)
	private Integer viewCount = 0;

	@Column(nullable = false)
	private Integer answerCount = 0;

	@Column(nullable = false)
	private Integer voteCount = 0;

	@Column(nullable = false)
	private Long answerVoteSum = Long.valueOf(0);

	@Column(nullable = false)
	private double pop = 0;

	@Transient
	private List<String> tags;

	@Transient
	private List<QuestionTag> tagList;

	@Transient
	private String tag1;

	@Transient
	private String tag2;

	@Transient
	private String tag3;

	@Transient
	private String tag4;

	@Transient
	private String tag5;

	@NotEmpty()
	@Type(type = "text")
	@Column(nullable = false)
	private String content;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date createdDate;

	/**
	 * 修改view count时，不修改
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date modifyDate;

	private Long modifierId;

	public void processVo(Question questionVo) {
		this.setId(questionVo.getId());
		this.setTitle(questionVo.getTitle());
		this.setContent(questionVo.getContent());
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public Long getModifierId() {
		return modifierId;
	}

	public void setModifierId(Long modifierId) {
		this.modifierId = modifierId;
	}

	public String getTag1() {
		return tag1;
	}

	public void setTag1(String tag1) {
		this.tag1 = tag1;
	}

	public String getTag2() {
		return tag2;
	}

	public void setTag2(String tag2) {
		this.tag2 = tag2;
	}

	public String getTag3() {
		return tag3;
	}

	public void setTag3(String tag3) {
		this.tag3 = tag3;
	}

	public String getTag4() {
		return tag4;
	}

	public void setTag4(String tag4) {
		this.tag4 = tag4;
	}

	public String getTag5() {
		return tag5;
	}

	public void setTag5(String tag5) {
		this.tag5 = tag5;
	}

	public Integer getViewCount() {
		return viewCount;
	}

	public void setViewCount(Integer viewCount) {
		this.viewCount = viewCount;
	}

	public Integer getAnswerCount() {
		return answerCount;
	}

	public void setAnswerCount(Integer answerCount) {
		this.answerCount = answerCount;
	}

	public Integer getVoteCount() {
		return voteCount;
	}

	public void setVoteCount(Integer voteCount) {
		this.voteCount = voteCount;
	}

	public void setPop(double pop) {
		this.pop = pop;
	}

	public double getPop() {
		return pop;
	}

	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public List<QuestionTag> getTagList() {
		return tagList;
	}

	public void setTagList(List<QuestionTag> tagList) {
		this.tagList = tagList;
	}

	public Long getAnswerVoteSum() {
		return answerVoteSum;
	}

	public void setAnswerVoteSum(Long answerVoteSum) {
		this.answerVoteSum = answerVoteSum;
	}
}
